﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.IO;
using System.Windows;
using System.Collections;
using System.Windows.Controls;
using System.Collections.Specialized;
using System.ComponentModel;

namespace ShapeConnectors.MaTrix
{
    class MaTran
    {
        public static int spt;
        //public static int[,] matran;
        public int Spt
        {
            get { return spt; }
            set { spt = value; }
        }
        public static int[,] a;

        public int[,] A
        {
            get { return a; }
            set { a = value; }
        }

        public struct Canh
        {
            public int d;

            public int D
            {
                get { return d; }
                set { d = value; }
            }
            public int c;

            public int C
            {
                get { return c; }
                set { c = value; }
            }
            public int tl;

            public int Tl
            {
                get { return tl; }
                set { tl = value; }
            }
        }
        public static List<Canh> DSCanh;
        public static List<int> DSDinh;

        public static void Docfile(string filename)
        {

            FileStream fp = new FileStream(filename, FileMode.Open);
            StreamReader SR = new StreamReader(fp);
            spt = Convert.ToInt32(SR.ReadLine());
            a = new int[spt, spt];
            //matran = new int[spt, spt];
            for (int i = 0; i < spt; i++)
            {
                string Line = SR.ReadLine();
                int[] G = new int[spt];
                G = XuLyDong(Line);
                for (int j = 0; j < spt; j++)
                {
                    a[i, j] = G[j];
                    //matran[i, j] = G[j];
                }
            }

            SR.Close();
            fp.Close();
        }
        public static int[] XuLyDong(string line)
        {
            string[] parts = line.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            return Array.ConvertAll<string, int>(parts, int.Parse);

        }
        public static void Ghifile(string filename)
        {
            FileStream fp = new FileStream(filename, FileMode.Create);
            StreamWriter SW = new StreamWriter(fp);
            SW.WriteLine(spt);
            for (int i = 0; i < spt; i++)
            {
                for (int j = 0; j < spt; j++)
                {
                    SW.Write(a[i, j]);
                    SW.Write("\t");
                }
                SW.WriteLine();
            }

            SW.Close();
            fp.Close();
        }
        public static void PhatSinh()
        {
            
    
            Random ran = new Random();
            spt = ran.Next(5, 20);
            a = new int[spt, spt];
            for (int i = 0; i < spt; i++)
                for (int j = i; j < spt; j++)
                {
                   
                    if (i == j)
                        a[i, j] = 0;
                    else
                    {
                        a[i, j] = ran.Next(0, 50);
                        a[j, i] = a[i, j];
                    }
                }

        }
        public static void ListCanh()
        {
            DSCanh = new List<Canh>();
            Canh canh=new Canh();
            for(int i=0;i<spt;i++)
                for (int j = i+1; j < spt; j++)
                {
                    if (a[i, j] != 0)
                    {
                        canh.D = i;
                        canh.C = j;
                        canh.Tl = a[i, j];
                        DSCanh.Add(canh);
                    }
                }
        }
        public static void ListDinh()
        {
            DSDinh = new List<int>();
            for (int i = 0; i < spt; i++)
            {
                DSDinh.Add(i);
            }
        }
    }
}
